/**
 * 
 */
package com.newture.lxz.controller.helper;

/**
 * @author hu.xiao
 *
 */
public class Result {
	private Boolean success;
	private String errorCode;
	private Object data;
	private String message;
	
	/**
	 * 统一返回结果的方法，不要再使用其它形式返回结果
	 * @param errorCode
	 * @param message
	 * @param data
	 */
	private static Result result(boolean isOK, String errorCode, String message, Object data) {
		Result result = new Result();
		result.setSuccess(isOK);
		result.setErrorCode(errorCode);
		result.setMessage(message);
		result.setData(data);
		return result;
	}

	/**
	 * 返回操作成功的结果
	 */
	public static Result success(Object data) {
		return result(true, null, null, data);
	}
	
	public static Result success() {
		return result(true, null, null, null);
	}
	
	/**
	 * 返回操作失败的结果
	 * @param errorCode
	 * @param message
	 * @param data
	 */
	public static Result failure(String errorCode, String message, Object data) {
		return result(false, errorCode, message, data);
	}
	
	public static Result failure(String errorCode, String message) {
		return result(false, errorCode, message, null);
	}	
	
	public static Result failure(String errorCode) {
		return result(false, errorCode, null, null);
	}

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;

	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}
